<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/12/29
 * Time: 11:20
 */

namespace app\common;


use Endroid\QrCode\QrCode;

class qr_code
{
    public static function get_qr_code($url,$size=300,$logo='')
    {
        $qrCode = new QrCode($url);
        $qrCode->setSize($size);
//        $qrCode->setEncoding('UTF-8');
//        $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
        $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]);
        $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]);
//        $qrCode->setLabel('Scan the code', 16, __DIR__.'/../assets/fonts/noto_sans.otf', LabelAlignment::CENTER);
        if($logo){
            $qrCode->setLogoPath($logo);
            $qrCode->setLogoWidth(80);
        }
//        $qrCode->setValidateResult(false);
        header("Content-type: ".$qrCode->getContentType());

        $data = $qrCode->getDataUri();
        return $data;
    }
}